<!DOCTYPE html>
<html lang="en">

<head>
  {include file="common/meta" /}
</head>

<body>
  <!-- 搜索 -->
  <div class="layui-row">


    <button class="layui-btn layui-btn-danger x-right" style="margin-top: 20px;margin-right: 20px;" onclick="recycle()">
      回收站
    </button>

  </div>
  <div class="x-body">
    <xblock>
      <button class="layui-btn layui-btn-danger" onclick="delAll()">
        <i class="layui-icon"></i>批量加入回收站
      </button>

      <span class="x-right" style="line-height:40px">
        共有数据：{$count} 条
      </span>
    </xblock>

    <table class="layui-table">
      <thead>
        <tr>
          <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
            </div>
          </th>
          <th>配置的标题</th>
          <th>配置的名称</th>
          <th>配置的类型</th>
          <th>配置的值</th>
          <th>操作</th>
      </thead>

      <tbody>
        {foreach $configList as $item}
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
              <i class="layui-icon">&#xe605;</i>
            </div>
          </td>
          <td>{$item.title}</td>
          <td>{$item.key}</td>
          {if condition = "$item.type == 'text'"}
          <td>文本类型</td>
          <td>{$item['value']}</td>

          {else /}
          <td>文件类型</td>
          <td>
            <img src="{$item.value}" alt="">
          </td>
          {/if}
          <td>
            <a title="编辑" href="{:url('admin/config/edit', ['id' => $item.id])}"
              class="layui-btn layui-btn-sm layui-btn-normal">
              编辑
            </a>
            <a title="删除" href="javascript:;" onclick="delOne(`{$item.id}`)"
              class="layui-btn layui-btn-sm layui-btn-danger">
              添加回收站
            </a>
          </td>
        </tr>
        {/foreach}
      </tbody>
    </table>

    <div class="page">
      {$pagestr}
    </div>

  </div>
</body>

<script>
  // 单个删除
  function delOne(id) {
    layer.confirm('确认要删除吗？', function (index) {
      layer.close(index);
      del(id);
    })
  }

  function recycle() {
    window.location.href = "{:url('admin/config/recycle')}"
  }

  // 批量删除
  function delAll() {
    var ids = tableCheck.getData()
    layer.confirm('确认要删除吗？', function (index) {
      //将数组转换为字符串
      var data = ids.join(',');
      del(data)
    })
  }

  // 调用删除方法
  function del(data) {
    // 序列化 将对象转换为参数形式
    var params = {
      ids: data,
    }

    params = $.param(params);

    $.ajax({
      type: "POST",
      url: `{:url('admin/config/del')}`,
      data: params,
      dataType: "json",
      success: function (data) {
        if (data.result) {
          // 成功
          layer.msg(data.msg, {
            icon: 1,
            time: 2000,
          }, function () {
            // 收藏成功刷新界面
            location.reload();
          })
        } else {
          // 失败
          layer.msg(data.msg);
        }
      }
    })
  }
</script>

</html>